package com.fdb.efp.nls.service.impl;

import com.fdb.basic.framework.core.base.FrameworkService;
import com.fdb.efp.nls.service.dao.ReconciliationDocumentsDao;
import com.fdb.efp.nls.service.domain.ReconciliationDocuments;
import com.fdb.efp.nls.service.facade.ReconciliationDocumentsService;
import com.fdb.efp.nls.service.vo.ReconciliationDocumentsVo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

/**
 * 
 * 并账文件实现类
 * 
 * @author liyakui
 * @since 2019年1月21日 下午8:39:43
 * @version 1.0
 */
@Service("reconciliationDocumentsService")
public class ReconciliationDocumentsServiceImpl implements ReconciliationDocumentsService, FrameworkService {
	private final static Logger logger = LoggerFactory.getLogger(ReconciliationDocumentsServiceImpl.class);
	@Autowired
	private ReconciliationDocumentsDao reconciliationDocumentsDao;

	/**
	 * 
	 * 查询汇总文件汇总金额
	 * 
	 * @param reconciliationDocumentsVo
	 * @return
	 * @throws Exception
	 * @author liyakui
	 * @since 2019年1月23日 下午8:20:35
	 * @version 1.0
	 */
	@Override
	public Map<String, BigDecimal> queryRecDocSumBal(ReconciliationDocumentsVo reconciliationDocumentsVo)
			throws Exception {
		logger.info("查询数据开始！参数：" + reconciliationDocumentsVo);
		Map<String, BigDecimal> map = null;
		try {
			ReconciliationDocuments reconciliationDocuments = new ReconciliationDocuments();
			beanCopy(reconciliationDocumentsVo, reconciliationDocuments);
			map = reconciliationDocumentsDao.queryRecDocSumBal(reconciliationDocuments);
			logger.info("查询数据成功！返回结果：" + map);
		} catch (Exception e) {
			logger.debug("查询数据异常！" + e.getMessage());
			throw e;
		}
		return map;
	}

	/**
	 * 
	 * 新增数据
	 * 
	 * @param record
	 * @return
	 * @author liyakui
	 * @since 2019年1月22日 下午5:56:19
	 * @version 1.0
	 */
	@Override
	public int insert(ReconciliationDocumentsVo reconciliationDocumentsVo) {
		logger.info("新增数据开始!" + reconciliationDocumentsVo);
		int count = 0;
		try {
			ReconciliationDocuments reconciliationDocuments = new ReconciliationDocuments();
			beanCopy(reconciliationDocumentsVo, reconciliationDocuments);
			count = reconciliationDocumentsDao.insert(reconciliationDocuments);
			logger.info("新增数据成功！新增条数：" + count);
		} catch (Exception e) {
			count = -1;
			e.printStackTrace();
			logger.debug("插入数据异常！" + e.getMessage());
		}
		return count;
	}

	/**
	 * 
	 * 根据日期更新数据
	 * 
	 * @param reconciliationDocumentsVo
	 * @return
	 * @throws Exception
	 * @author liyakui
	 * @since 2019年1月23日 下午8:23:26
	 * @version 1.0
	 */
	@Override
	public int updateReconciliationDocuments(ReconciliationDocumentsVo reconciliationDocumentsVo) throws Exception {
		logger.info("更新数据开始！参数：" + reconciliationDocumentsVo);
		int count = 0;
		try {
			ReconciliationDocuments reconciliationDocuments = new ReconciliationDocuments();
			beanCopy(reconciliationDocumentsVo, reconciliationDocuments);
			count = reconciliationDocumentsDao.updateReconciliationDocuments(reconciliationDocuments);
			logger.info("更新数据成功！更新条数：" + count);
		} catch (Exception e) {
			logger.debug("更新数据异常！" + e.getMessage());
			throw e;
		}
		return count;
	}

	/**
	 * 
	 * 批量插入数据
	 * 
	 * @param reconciliationDocumentsVos
	 * @return
	 * @author liyakui
	 * @since 2019年1月31日 下午2:43:04
	 * @version 1.0
	 */
	@Override
	public int batchInsert(List<ReconciliationDocumentsVo> reconciliationDocumentsVos) throws Exception {
		logger.info("批量插入数据开始！参数：" + reconciliationDocumentsVos);
		int count = 0;
		try {
			List<ReconciliationDocuments> reconciliationDocuments = (List<ReconciliationDocuments>) beansCopy(reconciliationDocumentsVos,
					ReconciliationDocuments.class);
			count = reconciliationDocumentsDao.batchInsert(reconciliationDocuments);
			logger.info("批量插入数据成功！条数：" + count);
		} catch (Exception e) {
			logger.debug("批量插入数据异常！" + e.getMessage());
			throw e;
		}
		return 0;
	}

	@Override
	public int insertSelective(ReconciliationDocumentsVo record) {
		// TODO Auto-generated method stub
		return 0;
	}




}
